package UI_vente;

import GestionBilleterie.Tarif;
import GestionPlannification.Piece;
import GestionPlannification.Representation;
import java.util.List;
import javax.swing.ImageIcon;

/**
 *
 * @author Elsa Ferrare, Alexandre Becquet
 */
public class Panel_voirPiece extends javax.swing.JPanel {
    private Piece maPiece=null;
    private Representation representationSelect=null;
    private Tarif tarifSelect;
    private static final int NB_MAX_RESA_PERSONNE=20;
    private Frame_vente maFrame;
    private int nbPlaceReserv=0;

    /** Creates new form Panel_voirPiece */
    public Panel_voirPiece(Piece p,Frame_vente frame) {
        this.maFrame=frame;
        this.maPiece=p;
        initComponents();
        
        this.jLabelTitre.setText(p.getTitre());
        this.jLabelGenre.setText("Genre : "+p.getGenre().toString());
        String auteurs = p.getAuteursString();
        this.jLabelAuteurs.setText("Auteurs : "+auteurs);
        String acteurs = p.getActeursString();
        this.jLabelActeurs.setText("Acteurs : "+acteurs);
        this.jTextArea1.setText("Resumé :\n"+p.getResume());

        ImageIcon icon = new ImageIcon("image/"+p.getId()+".jpg","Affiche");
        this.jLabelImage.setIcon(icon);

        List lesRepresentations=this.maPiece.getRepresentations();
        for(int i=0;i<lesRepresentations.size();i++){
            this.jComboBoxRepresentations.addItem(lesRepresentations.get(i));
        }

        List lesTarifs=Tarif.findEntities();
        for(int i=0;i<lesTarifs.size();i++){
            this.jComboBoxTarifs.addItem(lesTarifs.get(i));
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelImage = new javax.swing.JLabel();
        jLabelTitre = new javax.swing.JLabel();
        jLabelGenre = new javax.swing.JLabel();
        jLabelAuteurs = new javax.swing.JLabel();
        jLabelActeurs = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jComboBoxRepresentations = new javax.swing.JComboBox();
        jButtonValider = new javax.swing.JButton();
        jButtonAnnuler = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabelNbPlace = new javax.swing.JLabel();
        jLabelTarif = new javax.swing.JLabel();
        jComboBoxTarifs = new javax.swing.JComboBox();
        jComboBoxNbPlaceReserv = new javax.swing.JComboBox();
        jLabelPlacesdispo = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();

        setBackground(new java.awt.Color(255, 255, 102));
        setOpaque(false);

        jLabelTitre.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelTitre.setText("Titre");
        jLabelTitre.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(204, 0, 0)));

        jLabelGenre.setText("Genre :");

        jLabelAuteurs.setText("Auteurs :");

        jLabelActeurs.setText("Acteurs :");

        jLabel7.setText("CHOISISSEZ LA SEANCE PUIS LE NOMBRE DE PLACE(S) : ");

        jComboBoxRepresentations.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxRepresentationsActionPerformed(evt);
            }
        });

        jButtonValider.setText("Valider");
        jButtonValider.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonValiderActionPerformed(evt);
            }
        });

        jButtonAnnuler.setText("Annuler");
        jButtonAnnuler.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAnnulerActionPerformed(evt);
            }
        });

        jTextArea1.setBackground(new java.awt.Color(255, 255, 102));
        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("Resume");
        jTextArea1.setWrapStyleWord(true);
        jTextArea1.setDisabledTextColor(new java.awt.Color(255, 255, 102));
        jTextArea1.setOpaque(false);
        jTextArea1.setSelectionColor(new java.awt.Color(255, 255, 102));
        jScrollPane1.setViewportView(jTextArea1);

        jLabelNbPlace.setText("Nombre places");

        jLabelTarif.setText("Tarif");

        jComboBoxTarifs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxTarifsActionPerformed(evt);
            }
        });

        jComboBoxNbPlaceReserv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxNbPlaceReservActionPerformed(evt);
            }
        });

        jLabelPlacesdispo.setText("Nb place disponibles : ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabelImage, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelActeurs)
                            .addComponent(jLabelGenre)
                            .addComponent(jLabelTitre, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelAuteurs)))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(170, 170, 170)
                        .addComponent(jButtonValider)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonAnnuler))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelNbPlace)
                                    .addComponent(jLabelTarif))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBoxTarifs, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBoxNbPlaceReserv, 0, 116, Short.MAX_VALUE)))
                            .addComponent(jComboBoxRepresentations, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelPlacesdispo)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelTitre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelGenre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelAuteurs)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelActeurs))
                    .addComponent(jLabelImage, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxRepresentations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelPlacesdispo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTarif)
                    .addComponent(jComboBoxTarifs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNbPlace)
                    .addComponent(jComboBoxNbPlaceReserv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonValider)
                    .addComponent(jButtonAnnuler))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxRepresentationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxRepresentationsActionPerformed
        representationSelect=(Representation)this.jComboBoxRepresentations.getSelectedItem();
        changerNbPlace();
}//GEN-LAST:event_jComboBoxRepresentationsActionPerformed

    private void jButtonValiderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonValiderActionPerformed
        // TODO add your handling code here:
        if(representationSelect!=null && tarifSelect!=null && nbPlaceReserv!=0)
        this.maFrame.validationReservation(representationSelect, tarifSelect, nbPlaceReserv);
}//GEN-LAST:event_jButtonValiderActionPerformed

    private void jButtonAnnulerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAnnulerActionPerformed
        this.maFrame.chargerlesPieces();
}//GEN-LAST:event_jButtonAnnulerActionPerformed

    private void changerNbPlace(){
        if(representationSelect!=null && tarifSelect!=null){
            this.jComboBoxNbPlaceReserv.removeAllItems();
            int nbPlace;
            int nbPlaceDispo=representationSelect.nbPlacesDisponibles(tarifSelect.getId());
            if(nbPlaceDispo<NB_MAX_RESA_PERSONNE){
                nbPlace=nbPlaceDispo;
            }else if(nbPlaceDispo==0){
                nbPlace=0;
                this.jComboBoxNbPlaceReserv.setVisible(false);
            }else{
                nbPlace=NB_MAX_RESA_PERSONNE;
            }
            for(int i=1;i<nbPlace+1;i++){
                this.jComboBoxNbPlaceReserv.addItem(i);
            }
            this.jLabelPlacesdispo.setText("Nb place disponibles : "+representationSelect.nbPlacesDisponibles(tarifSelect.getId()));
        }
    }
    private void jComboBoxTarifsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxTarifsActionPerformed
        tarifSelect = (Tarif) this.jComboBoxTarifs.getSelectedItem();
        changerNbPlace();
}//GEN-LAST:event_jComboBoxTarifsActionPerformed

    private void jComboBoxNbPlaceReservActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxNbPlaceReservActionPerformed
        // TODO add your handling code here:
        nbPlaceReserv=this.jComboBoxNbPlaceReserv.getSelectedIndex()+1;
    }//GEN-LAST:event_jComboBoxNbPlaceReservActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAnnuler;
    private javax.swing.JButton jButtonValider;
    private javax.swing.JComboBox jComboBoxNbPlaceReserv;
    private javax.swing.JComboBox jComboBoxRepresentations;
    private javax.swing.JComboBox jComboBoxTarifs;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelActeurs;
    private javax.swing.JLabel jLabelAuteurs;
    private javax.swing.JLabel jLabelGenre;
    private javax.swing.JLabel jLabelImage;
    private javax.swing.JLabel jLabelNbPlace;
    private javax.swing.JLabel jLabelPlacesdispo;
    private javax.swing.JLabel jLabelTarif;
    private javax.swing.JLabel jLabelTitre;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

}
